<?php

namespace app\api\model\user;

use app\common\model\settings\Region;
use app\common\model\user\UserViolation as UserViolationModel;

/**
 * 用户收货地址模型
 */
class UserViolation extends UserViolationModel
{
    /**
     * 隐藏字段
     */
    protected $hidden = [
        'app_id',
        'create_time',
        'update_time'
    ];

    /**
     * 获取列表
     */
    public function getList($user_id)
    {
        return $this->where('user_id', '=', $user_id)->select();
    }

    /**
     * 新增收货地址
     */
    public function add( $user, $data )
    {
        // 添加收货地址
        $this->startTrans();
        try {
            $welfare_id = $this->insertGetId([
                'realname'   => $data['realname'],
                'phone'      => $data['phone'],
                'car_number' => $data['car_number'],
                'type'       => $data['type'],
                'user_id'    => $user['user_id'],
                'app_id'     => self::$app_id,
                'create_time'=>time()
            ]);
            $this->commit();
            return true;
        } catch (\Exception $e) {
            $this->error = $e->getMessage();
            $this->rollback();
            return false;
        }
    }
}